/**
*      author: Y_Yao
*      created: 2025-04-03 17:25:58
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 7;
int n,x;
stack<int> st;
string s;

void solve()
{
    cin >> n >> x;
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == 'U')
        {
            if(!st.empty())
            {
                s[i] = 0;
                s[st.top()] = 0;
                st.pop();
            }
        }
        else st.push(i);
    }
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == 'U')
        {
            x = x / 2;
        }
        else if(s[i] == 'L')
        {
            x = x * 2;
        }
        else if(s[i] == 'R')
        {
            x = x * 2 + 1;
        }
    }
    cout << x << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}